package com.ac.scum.log.web.model.player.controller;

import com.ac.common.core.exception.BaseException;
import com.ac.common.core.result.Result;
import com.ac.scum.log.bean.Player;
import com.ac.scum.log.bean.PlayerVO;
import com.ac.scum.log.web.model.player.service.PlayerService;
import com.ac.scum.log.web.utils.user.CurrentUserUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 玩家
 */
@Slf4j
@RestController
@RequestMapping("player")
@AllArgsConstructor
public class PlayerController {
    private final PlayerService playerService;

    /**
     * 玩家名称模糊匹配。
     *
     * @param name 用于查询的玩家名称，支持部分匹配。
     * @return 返回一个结果对象，其中包含查询到的玩家列表。
     * @throws BaseException 如果查询过程中发生错误，则抛出基础异常。
     */
    @GetMapping("by/{name}")
    public Result<List<Player>> getPlayerByName(@PathVariable String name) throws BaseException {
        return Result.ok(playerService.findPlayersByName(CurrentUserUtil.getCurrentServerId(), name));
    }

    /**
     * 玩家分页接口。
     */
    @PostMapping("page/{current}/{size}")
    public Result<IPage<PlayerVO>> getPlayerPage(@PathVariable Long current, @PathVariable Long size, @RequestBody PlayerVO player) throws BaseException {
        return Result.ok(playerService.findPlayerPage(CurrentUserUtil.getCurrentServerId(), player, current, size));
    }
}
